let obj = {
    name: 'zl'
}

Object.defineProperty(obj, 'name', {
    set() {
        console.log('obj的name属性被设置')
    },
    get() {
        console.log('obj的name属性被读取')
    }
})

// console.log(obj.name)
// obj.name = 'zhl'

let user = {
    name: 'zhl',
    age: 18
}

Object.keys(user).forEach(key => {
   let value = user[key]
    Object.defineProperty(user, key, {
        set(newValue) {
            console.log(`user中的${key}被设置`)
            value = newValue
        },
        get() {
            console.log(`user中的${key}被读取`)
            return value
        }
       
    })
})
user.name = 'zl'
user.age = 29
console.log(user.name)
console.log(user.age)
